package fitnesshub.mapper;

import com.github.pagehelper.Page;
import fitnesshub.pojo.dto.MemberPageQueryDTO;
import fitnesshub.pojo.entity.Member;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface MemberMapper {
    /**
     * 根据用户名查询会员
     * @param username
     * @return
     */
    @Select("select * from member where username = #{username}")
    Member getByUsername(String username);

    /**
     * 根据id查询会员
     * @param memberId
     * @return
     */
    @Select("select * from member where member_id = #{memberId}")
    Member getById(Integer memberId);

    /**
     * 更新会员信息
     * @param member
     */
    void update(Member member);

    /**
     * 通过id查密码
     * @param memberId
     * @return
     */
    @Select("select member.password from member where member_id = #{memberId}")
    String getPasswordById(Integer memberId);


    /**
     * 用户分页
     * @param memberPageQueryDTO
     * @return
     */
    Page<Member> pageQuery(MemberPageQueryDTO memberPageQueryDTO);


    /**
     * 查询用户名是否存在
     *
     * @param username
     * @return
     */
    @Select("select * from member where username = #{username}")
    Member selectByUsername(String username);

    /**
     * 插入用户
     *
     * @param member
     */
    @Insert("insert into member (username, password, gender, contact, member_type, registration_time, age, member_name)" +
            "VALUES " +
            "(#{username},#{password},#{gender},#{contact},#{memberType},#{registrationTime},#{age},#{memberName})")
    void insert(Member member);
}
